import unittest
from py41.test_unit import test003
# import HTMLTestRunner
from HTMLTestRunner import HTMLTestRunner
class test001(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        print("初始化")

    def test_case001(self):
        print("testcase001")

    def test_case002(self):
        print("testcase002")

    def test_case003(self):
        print("testcase003")

    @classmethod
    def tearDownClass(cls):
        print("资源回收")

class test002(unittest.TestCase):


    def setUp(self):
        print("初始化")

    def test_case001(self):
        print("testcase001")

    def test_case002(self):
        print("testcase002")

    def test_case003(self):
        print("testcase003")


    def tearDown(self):
        print("资源回收")
if __name__ == '__main__':
    # unittest.main()

    suite=unittest.TestSuite()#实例化一个测试集对象
    # suite.addTests(unittest.TestLoader().loadTestsFromTestCase(test001))#添加整个类至测试集

    suite.addTests(unittest.TestLoader().loadTestsFromModule(test003))#添加模块至测试集
    # suite.addTests(unittest.TestLoader().loadTestsFromName("test001.test_case001"))#按照用例名称添加至测试集
    # runner=unittest.TextTestRunner()#实例化一个runner负责执行
    # runner.run(suite)#执行测试集
    # unittest.TextTestRunner().run(suite)

    #import HTMLTestRunner,导入主包
    # with open("test.html","w",encoding="utf8") as file:
    #     runner=HTMLTestRunner.HTMLTestRunner(stream=file,verbosity=1,title="测试报告",description="unitetest 简单测试报告")
    #     runner.run(suite)

    # from HTMLTestRunner import HTMLTestRunner,导入子包
    with open("test.html","w",encoding="utf8") as file:
        runner=HTMLTestRunner(stream=file,verbosity=1,title="测试报告",description="unitetest 简单测试报告")
        runner.run(suite)